package org.example.hansp.array_.two_dimensional_array;

public class FindTwoShortest {
    public static void main(String[] args) {
        int[][] matrix = {{1, 2}, {0,0},{1,1},{2,2}};
        double[] twoShortest = findTwoShortest(matrix);
        System.out.println(twoShortest[0]);
        System.out.println(matrix[(int)twoShortest[1]][0]+","+matrix[(int)twoShortest[1]][1]);
        System.out.println(matrix[(int)twoShortest[2]][0]+","+matrix[(int)twoShortest[2]][1]);
    }
    public static double[]findTwoShortest(int[][] matrix) {
        int m = matrix.length;
        int temp=0;
        int temp1=1;

        double [] array = new double[3];

        double sqrt = Math.sqrt(Math.pow((matrix[0][0] - matrix[1][0]), 2) + Math.pow((matrix[0][1] - matrix[1][1]), 2));
        for(int i=1; i<m-1; i++) {
            for(int j=i+1; j<m; j++) {
                double newShot=Math.sqrt(Math.pow((matrix[i][0] - matrix[j][0]), 2) + Math.pow((matrix[i][1] - matrix[j][1]), 2));
                if(sqrt>newShot){
                    sqrt=newShot;
                    temp=i;
                    temp1=j;
                }
            }


        }
        array[0]=sqrt;
        array[1]=temp;
        array[2]=temp1;
        return array;

    }
}
